@echo off
del *.bak /s
del *.ddk /s
del *.edk /s
del *.lst /s
del *.lnp /s
del *.mpf /s
del *.mpj /s
del *.obj /s
del *.omf /s
del *.plg /s
del *.rpt /s
del *.tmp /s
del *.__i /s
del *.crf /s
del *.o /s
del *.d /s
del *.axf /s
del *.tra /s
del *.dep /s           
del JLinkLog.txt /s
del build_log.txt /s

del *.iex /s
del *.htm /s
del *.map /s

::set UV=C:\Keil_v5\UV4\UV4.exe
set UV="D:\Program Files\Keil_v5\UV4\UV4.exe"

for /f "usebackq delims=" %%j in (`dir /s /b %cd%\*.uvprojx`) do (
if exist %%j (
set UV_PRO_PATH="%%j"))


echo ---------------------------------------------------------------
echo Author:YUJQ
echo Init building ...
echo >build_log.txt

%UV% -j0 -b %UV_PRO_PATH% -l build_log.txt

for /f "delims=[" %%i in (build_log.txt) do echo %%i


echo %errorlevel%

if %errorlevel% LEQ 1 goto ok
if %errorlevel% NEQ 0 goto err

:ok
HexView\hexview.exe Output\Y2008_MCU_APP.hex /S /FR:0x0803FD00,4 /FP:55AA55AA /XI:16 -o Output\Y2008_MCU_APP_PP_TMP.hex
HexView\hexview.exe Output\Y2008_MCU_APP_PP_TMP.hex /S /FR:0x0803FE00,4 /FP:55AA55AA /XI:16 -o Output\Y2008_MCU_APP_PP_Temp_1.hex
HexView\hexview.exe Output\Y2008_MCU_APP_PP_Temp_1.hex /S /FR:0x0803F000,19 /FP:18040130303030303030303030303030303031 /XI:16 -o Output\Y2008_MCU_APP_PP_Temp_2.hex
HexView\hexview.exe Output\Y2008_MCU_APP_PP_Temp_2.hex /S /FR:0x0803E400,36 /FP:31305F36303130303139363241415F31315F3454545F31325F3138303431383030303031 /XI:16 -o Output\Y2008_MCU_APP_PP_Temp.hex
HexView\hexview.exe Output\Y2008_MCU_APP_PP_Temp.hex /S /FR:0x0803F800,4 /FP:00000000 /XI:16 -o Output\Y2008_MCU_APP_PP.hex
DEL Output\Y2008_MCU_APP_PP_TMP.hex
DEL Output\Y2008_MCU_APP_PP_Temp.hex
DEL Output\Y2008_MCU_APP_PP_Temp_1.hex
DEL Output\Y2008_MCU_APP_PP_Temp_2.hex
set /a ret=0
echo exit %ret%
exit /b %ret%
goto done

:err
set /a ret=1
echo exit %ret%
exit /b %ret%

goto done

:done
